import { selectionBoxMixin } from '../../common/mixins/selectionBox';
const name = 'grimm-radio';
export default {
  name,
  mixins: [selectionBoxMixin],
  props: {
    /**
     * 可选值：true|false
     * false：表示同一个radio点击第二次的时候，取消选中
     * true：和原生的radio行为一致
     */
    original: {
      type: [Boolean, String],
      default: false,
    },
    className: {
      default: name,
    },
    falseIcon: {
      type: String,
      default: 'radio',
    },
    trueIcon: {
      type: String,
      default: 'radio-active',
    },
  },
  computed: {
    _isChecked() {
      // 此处有坑[1] == 1为true
      /* eslint-disable eqeqeq */
      return this.strict
        ? this.value === this.name
        : JSON.stringify(this.value) == JSON.stringify(this.name);
    },
  },
  methods: {
    _onInnerClick() {
      if (this.original && !this._isChecked) {
        this._onRadioIntercept(() => {
          this.$emit('input', this.name);
        }, this.name);
      } else if (!this.original) {
        const value = this._isChecked ? '' : this.name;
        this._onRadioIntercept(() => {
          this.$emit('input', value);
        }, value);
      }
    },
  },
};
